package com.bnz.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bnz.entity.Student;
import com.bnz.entity.vo.StudentVo;
import com.bnz.service.StudentService;
import com.bnz.util.PageResult;
import com.bnz.util.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // 注入到容器中，将java对象转为json格式
@RequestMapping("student")
public class StudentController {

    @Reference // 从zookeeper注册中心里取服务
    private StudentService studentService;

    // 1、查询全部数据
    @GetMapping("list")
    public R findAll(){
        System.out.println(studentService);
        List<Student> all = studentService.findAll();
        return R.ok().data("list",all);
    }
    /**
     * 2. 条件查询带分页
     */
    @PostMapping("search")
    public R search(int page, int pagesize, @RequestBody StudentVo vo){
        PageResult<Student> pr = studentService.search(page, pagesize, vo);
        return R.ok().data("pr",pr);
    }

    /**
     * 3. 添加学生
     */
    @PostMapping("add")
    public R add(@RequestBody Student student){
        studentService.add(student);
        return R.ok().message("添加成功！");
    }

}
